package com.ghsc.ghxc.jsb.ui.live.shopping

import androidx.lifecycle.MutableLiveData
import com.cn.appcore.base.BaseViewModel
import com.cn.appcore.ext.executeResponse
import com.cn.appcore.http.bean.BaseResponse
import com.ghsc.ghxc.jsb.api.ApiMarket
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 项目：GuoHuaMall
 * 包名：com.ghsc.ghxc.ui.live.shopping
 * 类名：LiveCarViewModel
 * 创建时间：2023/7/26 22:38
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
class LiveCarViewModel:BaseViewModel() {




    /**
     *  商品列表。全部
     * @param page  页码
     */
    var onZbCartListData = MutableLiveData<BaseResponse<LiveProductResult>>()
    fun onZbCartListMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onZbCartListData(paras) }
            executeResponse(
                response,
                { onZbCartListData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }
//
//    /**
//     *  直播_历史商品列表
//     * @param page  页码
//     */
//    var onHistoryProductListData = MutableLiveData<BaseResponse<LiveProductResult>>()
//    fun onHistoryProductListMethod(paras:String) {
//        launch {
//            val response = withContext(Dispatchers.IO) { ApiMarket.service.onHistoryProductListData(paras) }
//            executeResponse(
//                response,
//                { onHistoryProductListData.value = response },
//                { againLoginMsg.value = response.msg }
//            ) { errorMsg.value = response.msg }
//        }
//    }
//    /**
//     *  直播_上架购物车商品列表
//     * @param page  页码
//     */
//    var onListCartData = MutableLiveData<BaseResponse<LiveProductResult>>()
//    fun onListCartMethod(paras:String) {
//        launch {
//            val response = withContext(Dispatchers.IO) { ApiMarket.service.onListCartData(paras) }
//            executeResponse(
//                response,
//                { onListCartData.value = response },
//                { againLoginMsg.value = response.msg }
//            ) { errorMsg.value = response.msg }
//        }
//    }
//
//
    /**
     *  直播_设置讲解商品
     */
    var onZbCartExplainData = MutableLiveData<BaseResponse<Any>>()
    fun onZbCartExplainMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onZbCartExplainData(paras) }
            executeResponse(
                response,
                { onZbCartExplainData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }

    /**
     *  直播_购物车添加商品
     */
    var onZbCartStatusData = MutableLiveData<BaseResponse<Any>>()
    fun onZbCartStatusMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onZbCartStatusData(paras) }
            executeResponse(
                response,
                { onZbCartStatusData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }

}